function trim(str) {
    return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

function validateSequences(size) {
	var seqArr = new Array();
	for (i=0; i < size; i++) {
		var seqElem = document.getElementById('sequence_' + i);
		if (seqElem) {
			seqArr[i] = seqElem.options[seqElem.selectedIndex].value;
		}
	}
	
	seqArr.sort();
	
	for (i=0; i < size-1; i++) {
		if (seqArr[i] == seqArr[i+1]) {
			alert('Cannot have 2 entries with same sequence number.');
			return false;
		}
	}
	
	return true;
}

function format_number(pnumber,decimals){  

    if (isNaN(pnumber)) { return 0};  
    if (pnumber=='') { return 0};  
    var snum = new String(pnumber);  
    var sec = snum.split('.');  
    var whole = parseFloat(sec[0]);  
    var result = '';  
    if(sec.length > 1){  
        var dec = new String(sec[1]);  
        dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));  
        dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));  
        var dot = dec.indexOf('.');  
        if(dot == -1){  
            dec += '.';  
            dot = dec.indexOf('.');  
        }  
        while(dec.length <= dot + decimals) { dec += '0'; }  
        result = dec;  
    } else{  
        var dot;  
        var dec = new String(whole);  
        dec += '.';  
        dot = dec.indexOf('.');  
        while(dec.length <= dot + decimals) { dec += '0'; }  
        result = dec;  
    }  
    return result;  
}
